package com.wutuo.aggragation.school.controller;

import cn.apestar.core.base.BaseMessage;
import com.wutuo.school.api.SchoolAPIService;
import com.wutuo.school.api.request.SchoolRequest;
import com.wutuo.school.api.response.SchoolResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 校区 <br>
 * 详细说明.
 * <p>
 *
 * @author lvh
 * @version 1.0
 */
@RestController @RequestMapping(value = "/schoolService", produces = "application/json")
public class SchoolController {

    private Logger logger = LoggerFactory.getLogger(SchoolController.class);

    @Autowired private SchoolAPIService schoolService;

    /**
     * 新增校区
     *
     * @param request
     */
    @RequestMapping(value = "/addorUpdate", method = RequestMethod.POST) public Object create(
        @RequestBody @Valid SchoolRequest request) {

        schoolService.save(request);
        return new BaseMessage();
    }

    /**
     * 删除校区
     *
     * @param userId
     */
    @RequestMapping(value = "/del/{id}", method = RequestMethod.GET) public Object del(
        @PathVariable("id") Long id) {

        schoolService.del(id);
        return new BaseMessage();
    }

    /**
     * 查询校区
     *
     * @param name
     * @return
     */
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public List<SchoolResponse> lisForPage(@RequestBody SchoolRequest request) {

        List list = schoolService.list(request);
        return list;
    }
}